package org.summerframework.component.upload.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.summerframework.component.mybatisplus.AbstractBasePlusService;
import org.summerframework.component.upload.file.model.dao.FileUserRelDAO;
import org.summerframework.component.upload.file.model.domain.FileUserRelDO;
import org.summerframework.component.upload.file.service.FileUserRelService;
import org.summerframework.component.upload.file.service.dto.FileUserRelDTO;
import org.summerframework.component.upload.file.service.dto.FileUserRelQueryDTO;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service("fileUserRelService")
public class FileUserRelServiceImpl extends AbstractBasePlusService<FileUserRelDAO, FileUserRelDTO, FileUserRelQueryDTO, FileUserRelDO> implements FileUserRelService {

    @Override
    public Wrapper<FileUserRelDO> getWrapper(FileUserRelQueryDTO query) {
        return Wrappers.<FileUserRelDO>lambdaQuery()
.eq(Objects.nonNull(query.getSize()), FileUserRelDO::getSize, query.getSize())
.orderBy(Objects.nonNull(query.getOrderByCreateTime()), query.getOrderByCreateTime() != null?query.getOrderByCreateTime():false, FileUserRelDO::getCreateTime)
.orderBy(Objects.nonNull(query.getOrderByUpdateTime()), query.getOrderByUpdateTime() != null?query.getOrderByUpdateTime():false, FileUserRelDO::getUpdateTime)
.orderBy(Objects.nonNull(query.getOrderById()), query.getOrderById() != null?query.getOrderById():false, FileUserRelDO::getId)
.eq(StringUtils.isNotBlank(query.getSuffix()), FileUserRelDO::getSuffix, query.getSuffix())
.eq(StringUtils.isNotBlank(query.getType()), FileUserRelDO::getType, query.getType())
.eq(Objects.nonNull(query.getUserId()), FileUserRelDO::getUserId, query.getUserId())
.eq(StringUtils.isNotBlank(query.getUrl()), FileUserRelDO::getUrl, query.getUrl())
.eq(Objects.nonNull(query.getFileId()), FileUserRelDO::getFileId, query.getFileId());
    }
}
